<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../img/asset-favico.ico">
        <title>登录</title>
        <link rel="stylesheet" href="../css/page-health-login.css" />
        <link rel="stylesheet" href="../plugins/elementui/index.css" />
        <script src="../plugins/jquery/dist/jquery.min.js"></script>
        <script src="../plugins/healthmobile.js"></script>
        <script src="../plugins/vue/vue.js"></script>
        <script src="../plugins/vue/axios-0.18.0.js"></script>
        <script src="../plugins/elementui/index.js"></script>
    </head>
    <body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div class="app" id="app">
        <!-- 页面头部 -->
        <div class="top-header">
            <span class="f-left"><i class="icon-back"></i></span>
            <span class="center">瑞通健康</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <div style="margin-left: 20px">手机快速登录</div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="login">
                <form id='login-form'>
                    <div class="input-row">
                        <label>手机号</label>
                        <div class="loginInput">
                            <input v-model="loginInfo.telephone" id='account' type="text" placeholder="请输入手机号">
                            <input id="validateCodeButton" @click="sendValidateCode()" type="button" style="font-size: 12px" value="获取验证码">
                        </div>
                    </div>
                    <div class="input-row">
                        <label>验证码</label>
                        <div class="loginInput">
                            <input v-model="loginInfo.validateCode" style="width:80%" id='password' type="password" placeholder="请输入验证码">
                        </div>
                    </div>
                    <div class="input-row" style="font-size: 12px">
                        <input type="checkbox" checked v-model="loginInfo.checkBox">
                        阅读并同意《瑞通健康用户协议》《瑞通健康隐私条款》
                    </div>
                    <div class="btn yes-btn"><a @click="login()" href="#">登录</a></div>
                </form>
            </div>
        </div>
    </div>
    </body>
    <script>
        var vue = new Vue({
            el:'#app',
            data:{
                loginInfo:{}//登录信息
            },
            methods:{
                //发送验证码
                sendValidateCode(){
                    //获取手机号
                    let telephone = this.loginInfo.telephone;
                    if (telephone == undefined || telephone == ""){
                        this.$message.error("请输入手机号")
                        return;
                    }
                    //手机号合规（全数字，11位，1开头，第二位 3456789）
                    let reg = /^1[3-9][0-9]{9}$/;
                    //正则表达方式，test（被检测字符串），正则匹配成功返回true
                    if (!reg.test(telephone)){
                        this.$message.error("手机号格式错误")
                        return;
                    }
                    //定时器技术，定时1分钟，按钮屏蔽(disabled="disabled")
                    /*
                    * js中有2个定时器
                    * setTimeout()定时一次
                    * setInterval()反复执行定时器
                    * */
                    let number = 60;
                    let btn = $("#validateCodeButton");
                    let Intid =  setInterval(function (){
                        //jquery设置标签的属性
                        //按钮屏蔽
                        btn.attr("disabled",true);
                        //显示时间倒计时
                        btn.val(number+"后重新发送")
                        number --;
                        if (number == 0){
                            btn.val("发送验证码")
                            btn.attr("disabled",false);
                            clearInterval(Intid)
                        }
                    },1000);

                    //发送请求
                    axios.get("/validateCodeController/sendCode.do?telephone="+telephone).then(res=>{
                        if (res.data.flag){
                            this.$message.success(res.data.message);
                        }else {
                            this.$message.error(res.data.message);
                        }
                    })
                },
                //登录
                login(){
                    //获取手机号
                    let telephone = this.loginInfo.telephone;
                    if (telephone == undefined || telephone == ""){
                        this.$message.error("请输入手机号")
                        return;
                    }
                    //手机号合规（全数字，11位，1开头，第二位 3456789）
                    let reg = /^1[3-9][0-9]{9}$/;
                    //正则表达方式，test（被检测字符串），正则匹配成功返回true
                    if (!reg.test(telephone)){
                        this.$message.error("手机号格式错误")
                        return;
                    }

                    let vcode = this.loginInfo.validateCode;
                    if (vcode == undefined || vcode == ""){
                        this.$message.error("请输入验证码")
                        return;
                    }
                    if (this.loginInfo.checkBox == undefined || this.loginInfo.checkBox == false){
                        this.$message.error("请阅读并同意《瑞通健康用户协议》《瑞通健康隐私条款》")
                    }
                    if (this.loginInfo.checkBox == true){
                        //发送请求
                        axios.post("/test/resign",this.loginInfo).then(res=>{
                            if (res.data.flag){
                                this.$message.success(res.data.message);
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                    }

                }
            },
            mounted : function (){
                //js操作cookie
                let cookie = document.cookie.split("=")[1];
                $("#account").val(cookie);
                //发送请求，提交cookie == 手机号， 使用手机号作为key ，保持时长为30分钟

            }
        });
    </script>
</html>